//  @ Project : GagalPanen
//  @ File Name : gametime.cpp
//  @ Date : 3/9/2011
//  @ Author : 
//
//

#include <assert.h>
#include "gametime.hpp"
#include "season.hpp"

GameTime::GameTime() : day_count_(0), // is this ok?
        day_time_(0) { // is this ok?

}

GameTime::GameTime(std::ifstream& is) : day_count_(0), day_time_(0) {
  is >> day_time_ >> day_count_;
}

void GameTime::save(std::ofstream& os) {
  os << day_time_ << " " << day_count_ << std::endl;
}

GameTime::~GameTime() {
  
}

int GameTime::getDayCount() {
  return day_count_;
}

int GameTime::getDayTime() {
  return day_time_;
}

void GameTime::increaseDay() {
  day_count_ = day_count_ + 1;
  day_time_ = 0;
}

void GameTime::increaseTime() {
  day_time_ = day_time_ + 1;
}

void GameTime::decreaseTime(int count) {
  day_time_ -= count;
}

int GameTime::getSeason() {
  int tot = 0;
  for (int i = 0; i < Season::getSeasonCount(); ++i) {
    tot += Season::getSeasonLength(i);
  }

  int jml = 0;
  for (int i = 0; i < Season::getSeasonCount(); ++i) {
    if (day_count_ % tot < jml + Season::getSeasonLength(i)) {
      return i;
    }
    jml += Season::getSeasonLength(i);
  }
  assert(false);
}

int GameTime::getSeasonLength() {
  int tot = 0;
  for (int i = 0; i < Season::getSeasonCount(); ++i) {
    tot += Season::getSeasonLength(i);
  }

  int jml = 0;
  for (int i = 0; i < Season::getSeasonCount(); ++i) {
    if (day_count_ % tot < jml + Season::getSeasonLength(i)) {
      return Season::getSeasonLength(i) - ((day_count_ % tot) - jml);
    }
    jml += Season::getSeasonLength(i);
  }
  assert(false);
}

